package com.acmedcare.framework.plugin.sample.data;

import com.acmedcare.framework.exchange.center.core.metadata.AgentContext;
import com.acmedcare.framework.exchange.center.core.metadata.IDataAgent;
import com.acmedcare.framework.plugin.sample.Application;
import com.acmedcare.framework.plugin.sample.dto.TaskRunner;
import com.acmedcare.framework.plugin.sample.repository.TaskRunnerMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.util.List;
import org.apache.ibatis.session.SqlSession;

public class DemoAgent implements IDataAgent<TaskRunner> {

  @Override
  public List<TaskRunner> doWork(AgentContext agentContext) {

    SqlSession session = null;
    try {
      TaskRunnerMapper mapper = (TaskRunnerMapper) Application.configurableApplicationContext.getBean("taskRunnerMapper");
      List<TaskRunner> taskRunners = mapper.selectList(new QueryWrapper<>());

      return taskRunners;
    } catch (Exception e) {
      e.printStackTrace();
      return null;
    } finally {

      if (session != null) {

        session.close();
      }
    }
  }
}
